package classes.Commands
{
	import components.editor.c_baseCollagesEditor;
	import components.editor.c_baseEditor;
	import components.editor.c_baseElement;
	import components.editor.c_textElement;
	
	public class c_insertTextCommand extends c_commandFromEditor {
		private var _index			: int;		
		public function c_insertTextCommand(a_editor: c_baseEditor) {
			super(a_editor);
		}
		
		override public function Execute():void {
			super.Execute();
			if (!_element) {
				_element 	= new c_textElement(editor.imageLayer);
				_index 		= _element.index;
				textElement.applyTextFormat(function(): void {
					textElement.text 		= _element.locale.DEFAULTTEXT;
					textElement.toCenter();
					editor.dragRect.link 	= _element;
				});
			} else {
				_element.setParent(editor.imageLayer, _index);
				editor.dragRect.link = _element;
			}
		}
		
		override public function unExecute():void {
			element.remove();
			super.unExecute();
		}
		
		protected function get textElement(): c_textElement {
			return _element as c_textElement; 
		}
		
		override public function dispose():void {
			_element.dispose();
		}		
	}
}